/**
 * 
 */
package com.wodsy.phoenix.dataservice.cms.service.impl;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.container.Main;
import com.wodsy.phoenix.datadao.base.IBaseDao;
import com.wodsy.phoenix.datadao.cms.dao.CmsHomePageCustomizePicDao;
import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.constants.HomePageObjectType;
import com.wodsy.phoenix.dataobject.cms.model.IdxCustomizePic;
import com.wodsy.phoenix.dataobject.cms.vo.IdxCustomizePicResp;
import com.wodsy.phoenix.dataservice.base.AbstractBaseService;
import com.wodsy.phoenix.dataservice.cms.aop.AfterOperation;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageCustomizePicService;

/**
 * @author bryan
 *
 */
@Service(interfaceClass = CmsHomePageCustomizePicService.class, interfaceName = "com.wodsy.phoenix.dataservice.cms.service.CmsHomePageCustomizePicService")
public class CmsHomePageCustomizePicServiceImpl extends
		AbstractBaseService<IdxCustomizePic, Integer> implements CmsHomePageCustomizePicService {
	
	@Autowired
	CmsHomePageCustomizePicDao cmsHomePageCustomizePicDao;
	
	@Override
	protected IBaseDao<IdxCustomizePic, Integer> getIBaseDao() {
		return cmsHomePageCustomizePicDao;
	}
	@Transactional(readOnly=true)
	@Override
	public IdxCustomizePicResp getOnlineCustomizePicRec() {
		IdxCustomizePicResp resp = new IdxCustomizePicResp();
		IdxCustomizePic pic = cmsHomePageCustomizePicDao.getOnlineCustomizePicRec();
		try {
			BeanUtils.copyProperties(resp,pic );
		} catch (IllegalAccessException | InvocationTargetException e) {
			logger.error("object copy error!", e);
		}
		return resp;
	}
	@Transactional(readOnly=true)
	@Override
	public Pager<IdxCustomizePic> searchHotGoodsRecByOrder(
			Pager<IdxCustomizePic> picRec, IdxCustomizePic picreq) {
		return cmsHomePageCustomizePicDao.searchHotGoodsRecByOrder(picRec, picreq);
	}
	@Transactional(readOnly=false)
	//@AfterManuallyOperation(objectId="#picId",objectStatus="#status",objectType=HomePageObjectType.CUSTOMIZEPIC)
	@Override
	public Integer updateCustomizePicStatus(int picId, int status) {
		return cmsHomePageCustomizePicDao.updateCustomizePicStatus(picId, status);
	}
	
	@Transactional(readOnly=false)
	//@AfterManuallyOperation(objectId="#picIds",objectStatus="#status",objectType=HomePageObjectType.CUSTOMIZEPIC)
	@Override
	public Integer updateCustomizePicStatus(Integer[] picIds, int status) {
		return cmsHomePageCustomizePicDao.updateCustomizePicStatus(picIds, status);
	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#customizePic.id",objectType=HomePageObjectType.CUSTOMIZEPIC,
	offlineTime="#customizePic.offlineTime",onlineTime="#customizePic.onlineTime" )
	@Override
	public Integer addCustomizePicRecommended(IdxCustomizePic customizePic) {
		Integer picId = cmsHomePageCustomizePicDao.addCustomizePicRecommended(customizePic);
		
		return picId;

	}
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#customizePic.id",objectType=HomePageObjectType.CUSTOMIZEPIC,
	offlineTime="#customizePic.offlineTime",onlineTime="#customizePic.onlineTime" )
	@Override
	public void updateCustomizePicRecommended(IdxCustomizePic customizePic) {
		cmsHomePageCustomizePicDao.updateCustomizePicRecommended(customizePic);
	}
	public static void main(String[] args) {
		Main.main(args);
	}
}
